package com.guonl.rabbitmq.spring;

import java.util.HashMap;
import java.util.Map;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringMain {
    public static void main(final String... args) throws Exception {
        AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
                "classpath:spring/rabbitmq-provider.xml");
        //RabbitMQ模板
        RabbitTemplate template = ctx.getBean(RabbitTemplate.class);
        //发送消息
//        template.convertAndSend("Hello, world!");
        Map<String, Object> msg = new HashMap<>();
        msg.put("data","hello,rabbmitmq!");
        template.convertAndSend("queue_one_key", msg);
        Thread.sleep(1000);// 休眠1秒
        ctx.destroy(); //容器销毁
    }
}
